<template>
  <div>
    <text-line :data-arr="dataArr" :label-width="100"/>
    <data-show v-if="model && model.type === 'FILE'" ref="DataShow" ></data-show>
  </div>
</template>

<script lang="ts">
  import { Vue, Component } from 'vue-property-decorator'
  import EnumModel from '@/models/EnumModel'
  import TextLine from '@/components/global/textLine/index.vue'
  import { TextItem } from '@/components/global/textLine/types'
  import ArticleModel from "@/models/ArticleModel";
  import AccountModel from "@/models/AccountModel";
  import { EnumType } from '@/models/types'
  import DataShow from './dataShow.vue'
  import { DataShowType } from './types'

  @Component({
    name: 'ArticleEnumDetal',
    components: {
      DataShow,
      TextLine
    }
  })
  export default class ArticleEnumDetal extends Vue{

    model: EnumModel | null = null
    dataArr: Array<TextItem> = []

    setDataArr() {
      const model = this.model!
      const dataArr = [
        {
          title: '标题',
          text: model.name
        },
        {
          title: '创建人',
          text: (model.createUser as AccountModel).name || ''
        },
        {
          title: '创建时间',
          text: model.createTimeStr
        },
        {
          title: '层次',
          text: `${model.tier + 1}`
        },
        {
          title: 'UUID',
          text: model.uuid
        },
        {
          title: '归属项目',
          text: (model.project as ArticleModel).name || ''
        },
        {
          title: '索引',
          text: model.index
        },
        {
          title: '类型',
          text: model.typeText
        },
        {
          title: '描述',
          text: model.description
        },
      ]
      if (model.type === EnumType.FILE)
      dataArr.splice(3, 0, {
        title: 'Path',
        text: model.path
      })
      this.dataArr = dataArr
    }

    show(id: string) {
      EnumModel.create({
        _id: id
      }).getDeatil<EnumModel>().then((eModel: EnumModel) => {
        this.model = eModel
        this.setDataArr()
        if (eModel.type === EnumType.FILE) {
          this.$nextTick(() => {
            (this.$refs.DataShow as DataShowType).show(eModel)
          })
        }
      })
    }
  }

</script>

<style scoped>

</style>
